package com.brower.project.net

import com.brower.project.utils.CookiePreferences
import okhttp3.Interceptor
import okhttp3.Response

class SaveCookiesInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val originalResponse = chain.proceed(chain.request())
        if (originalResponse.headers("Set-Cookie").isNotEmpty()) {
            val cookies = HashSet<String>()
            originalResponse.headers("Set-Cookie").forEach {
                cookies.add(it)
            }
            CookiePreferences.saveCookie(cookies)
        }

        return originalResponse
    }
}